package com.zlzkj.app.service;

import com.zlzkj.app.mapper.PlanItemMapper;
import com.zlzkj.app.model.PlanItem;
import com.zlzkj.app.util.IDGenerator;
import com.zlzkj.app.util.Page;
import com.zlzkj.core.sql.Row;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

//import com.zlzkj.core.mybatis.SqlRunner;
//import com.zlzkj.app.mapper.MonitorMapper;
//import com.zlzkj.app.model.Monitor;

@Service
@Transactional
public class PlanItemService {
    @Value("${PAGE_SIZE}")
    private int PAGE_SIZE;

    @Autowired
    private PlanItemMapper mapper;

//	@Autowired
//	private SqlRunner sqlRunner;

    //新增
    public Integer save(PlanItem planitem) {
        planitem.setId(IDGenerator.generator());
        return mapper.insert(planitem);
    }

    //根据id删除
    public Integer delete(String id){
        return mapper.deleteByPrimaryKey(id);
    }

    public Integer deleteByPlanId(String planid){
        return mapper.deleteByPlanId(planid);
    }

    public Integer deleteByPlanIds(String[]id){
        Map parmMap = new HashMap();
        parmMap.put("ids",id);
        return mapper.deleteByPlanIdMap(parmMap);
    }

    public Integer deletebyIds(String[]id){
        Map parmMap = new HashMap();
        parmMap.put("ids",id);
        return mapper.deleteByMap(parmMap);
    }

    //根据主键更新
    public Integer update(PlanItem plan){
        return mapper.updateByPrimaryKey(plan);
    }

    //根据主键查找
    public PlanItem findById(String id){
        return mapper.selectByPrimaryKey(id);
    }

    public  List<Row>  findByPlanId(String planid){

        return mapper.selectByPlanId(planid);
    }

    public List<Row> findByMap(Map<String,Object> map){
        return mapper.selectByMap(map);
    }

    public Page findByMap(Map<String,Object> parmMap, Integer nowPage) {
        if(nowPage == null) nowPage = 1;
        parmMap.put("start",(nowPage-1)*PAGE_SIZE);
        parmMap.put("end",PAGE_SIZE);
        return new Page(findByMap(parmMap),mapper.countByMap(parmMap),nowPage,PAGE_SIZE);
    }

}
